package com.esperia09.webservice.mixibot.outh.keeptoken;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.esperia09.webservice.mixibot.oauth.MixiTokenStruct;


public class TokenAccessor {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    
	public boolean saveToken(MixiTokenStruct tokens) {
		try {
			pm.makePersistent(tokens);
		} catch(Exception e) {
			// TODO: Error.
			return false;
		} finally {
			pm.close();
		}
		
		return true;
	}
	
	public MixiTokenStruct loadToken(String id) {
        String out = "";
        MixiTokenStruct tokens = null;
        
        // TODO: Search
        Query query = pm.newQuery(MixiTokenStruct.class);
        query.setFilter("empno == empnoParam");
        query.declareParameters("String empnoParam");
        try {
        	tokens = (MixiTokenStruct) query.execute(id);
        } finally {
            query.closeAll();
        }
        
        return tokens;
	}
}
